<!--排班表（整合 化缘）-->
<?php include('header.php');
						$person=$_SESSION['user'];
						$q=$person->getauth();
						$have=in_array('a1',$q);
						if (!$have){
						$url = "/libraryoa/view/login.php";
  						Header("Location: $url");
						}
?>

<body onLoad="init()">
 <script type="text/javascript">
//*******************二级联动部分***********************************
var element = new Array(8);
function day_and_time(big,small)
{ 
	this.big = big;
	this.small = small; 
}
element[0]= new day_and_time("请选择工作日","请选择时间段");
element[1] = new day_and_time("星期一","|12:30-16:00|16:00-18:00|18:00-22:30");  
element[2] = new day_and_time("星期二","|12:30-16:00|16:00-18:00|18:00-22:30");
element[3] = new day_and_time("星期三","|12:30-16:00|16:00-18:00|18:00-22:30");
element[4] = new day_and_time("星期四","|12:30-16:00|16:00-18:00|18:00-22:30");
element[5] = new day_and_time("星期五","");
element[6] = new day_and_time("星期六","|8:30-12:30|12:30-17:30|17:30-22:30");
element[7] = new day_and_time("星期日","|8:30-12:30|12:30-17:30|17:30-22:30");
function select() 
{
	with(document.creator.day) 
	{
		var big2 = options[selectedIndex].value; 
	}
	for(i = 0;i < element.length;i ++) 
	{
		if (element[i].big == big2) 
		{
			big3 = (element[i].small).split("|");
			for(j = 0;j < big3.length;j++) 
			{ 
				with(document.creator.time) 
				{ 
					length = big3.length; 
					options[j].text = big3[j]; 
					options[j].value = big3[j];
					var big4=options[selectedIndex].value;
				}
			}
			break;
		}
	}
	document.creator.newlocation.value=big2+";"+big4+",";
}
function init() 
{
	with(document.creator.day) 
	{
		length = element.length;
		for(k=0;k<element.length;k++) 
		{ 
			options[k].text = element[k].big; 
			options[k].value = element[k].big; 
		}
		options[selectedIndex].text = element[0].big; 
		options[selectedIndex].value = element[0].big;
	}
	with(document.creator.time) 
	{
		big3 = (element[0].small).split("|");
		length = big3.length;
		for(l=0;l<length;l++) 
		{ 
			options[l].text = big3[l]; 
			options[l].value = big3[l]; 
		}
		options[selectedIndex].text = big3[0]; 
		options[selectedIndex].value = big3[0];
	}
} 

//************************动态生成表格并显示数据库返回信息******************************
var xmlHttp;
xmlHttp = create_obj();
function create_obj(){
	var xmlHttp;
	xmlHttp = new XMLHttpRequest();
	return xmlHttp;
}
//发送请求
function process(){
	day = document.getElementById("day").value;
	time = document.getElementById("time").value;
	xmlHttp.open("GET","../control/rec_sec_tab.php?time="+time+"&day="+day,true);
	xmlHttp.onreadystatechange = handle_f;
	xmlHttp.send(null);	
}
//动态生成表格,用于显示数据库返回的信息
function handle_f(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status==200){
			result = xmlHttp.responseText;
			if(result != null){
				var table = '<table  id="my_stations" border=1 width="100%" >';
				var elements = result.split("----");
				for(i=0;i<elements.length-1;i++){
					table=table+'<tr><td width="25%">'+elements[i]+'</td><td  width="25%">'+''
					+'</td><td width="25%">'+document.creator.newlocation.value+
					'</td><td><input type="button" value="添加到值班表"'+ 
					'onclick="insert_into_worktable(' +i+')"'+'/></td></tr>';
				}
				var div = document.getElementById("result_table");
			    div.innerHTML = table;
			}
		}else{
			alert("出错了!!!!"+xmlHttp.statusText);
		}
	}
}
////************************表格中填充岗位信息******************************
function fill_station(){
	var rows = document.getElementById('my_stations').rows.length;
	for(i=0;i<rows;i++){
		document.getElementById('my_stations').rows[i].cells[1].innerHTML =document.getElementById('choose_station').value;		
	}
}
//**************************butto按钮提交记录到数据库****************************

function insert_into_worktable(i){
	name = document.getElementById('my_stations').rows[i].cells[0].innerHTML;
	time = document.creator.newlocation.value;
	station = document.getElementById("choose_station").value;
	 
	xmlHttp.open("GET","../control/insert_work_table.php?name="+name+"&time="+time+"&station="+station,true);
	xmlHttp.onreadystatechange = hand_insert;
	xmlHttp.send(null);	

	
}

function hand_insert(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status==200){
			result = xmlHttp.responseText;
			if(result != null){
				if(result=="成功插入")
					alert("已经将"+name+"---"+time+"---"+station+"添加至值班表!");
				else 
					alert("该学生已经存在值班表中，请勿重复添加！");
			}
		}else{
			alert("出错了!!!!"+xmlHttp.statusText);
		}
	}
}
</script>


<div id="mainbody"  >
<div class="col-lg-9" id="charge">
    <div  class="panel panel-primary">
   <div class="panel-heading">
      <h3 class="panel-title">值班管理</h3>
   </div>
   <div class="panel-body">
   </div>
   <form method="post" name="creator" enctype="multipart/form-data">
   <table><tr>  	
   	<td>筛选条件:</td>
   	<td><select name="day"  id="day" onChange = "select()"></select></td>  	
   	<td><select name="time"  id="time" onChange = "select()"></select></td>  	
   	<td><input type=text name="newlocation" maxlength=12 size=24 style="font-weight: bold"></td>
	<td><input type = "button" value ="筛选" onClick = "process()"/></td>
   	</tr></table>
   		</form>
  <table width="100%" border="2px">
  <tr>
  	<td id="haha" width="25%"><b>学生姓名</b></td>
  	<td width="25%">
  	<select id="choose_station" onChange="fill_station()">
  		<option value="借、还、分书岗">借、还、分书岗</option>
  		<option value="上书岗">上书岗</option>
  		<option value="书库管理岗">书库管理岗</option>
  		<option value="报刊岗">报刊岗</option>
  		<option value="机动岗">机动岗</option>
  		<option value="小循环">小循环</option>
  	</select>
  	</td>
  	<td width="25%"><b>工作时间</b></td><td><b>操作</b></td>
  </tr>
  </table>
  <div id="result_table"></div>
</div>


<?php include('foot.php') ?>